<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .pre{
            background-color: green;
            color: black;
        }
        .next{
            background-color: red;
            color: black;
        }
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <!-- START 右侧数据 -->
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <input type="text" name="relatedListingName" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">渠道:</label>
                            <div class="col-sm-2">
                                <select id="relatedChannelName" name="relatedChannelName"  class="form-control">
                                    <option value="">全部分类</option>
                                    <%for(var chan in channel){%>
                                    <option value="${chan.channelName}"  >${chan.channelName}</option>
                                    <%}%>
                                </select>
                            </div>

                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedSku" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">运营人员:</label>
                            <div class="col-sm-2">
                                <input type="text"  name="relatedOperateName" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">状态:</label>
                            <div class="col-sm-2">
                                <select id="flag" name="flag"  class="form-control">
                                    <option value="">全部</option>
                                    <option value="99">异常未处理</option>
                                    <option value="2">异常已处理</option>
                                </select>
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
            <!-- START 操作按钮 -->
            <form>
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
                    <i class="fa fa-plus" aria-hidden="true"></i> 导入SKU企划价
                </button>

                <button  class="layui-btn layui-btn-warm layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-sales-btn"  name="import-sales-btn">
                    <i class="fa fa-plus" aria-hidden="true"></i> 导入SKU售价
                </button>
                <button  class="price-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-download" aria-hidden="true"></i> 修改定价数据
                </button>
                <button  class="layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download"></i>
                    <a href="/excel/对照表SKU模板.xlsx" style="color: white" download>模板下载</a>
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>
            </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-side-pagination="server"
                   data-page-size="15"
                   data-url="/sea/operate/relatedSkuPrice/findByCnd.do"
                   class="table table-striped table-hover">
            </table>
            <!-- END 数据表格 -->

            <!-- END 右侧数据 -->
        </div>
    </div>
</div>

<div id="layer_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">定价范围</label>
                <div class="col-sm-2">
                    <input type="text" id="relatedBeginDate" name="relatedBeginDate" value="" class="form-control">
                </div>
                <div class="col-sm-2" >
                    <input type="text" id="relatedEndDate" name="relatedEndDate" value="" class="form-control">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">备注</label>
                <div class="col-sm-6" style="max-width: 300px">
                    <input type="text" id="relatedRemark" name="relatedRemark" value="" class="form-control">
                </div>
                <input id="id" name="id" hidden="hidden">
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload,laydate'}){}%>
<script>
    laydate.render({
        elem: '#relatedBeginDate',
        type: 'date',
        trigger: 'click', //修改触发方式
        format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#relatedEndDate',
        type: 'date',
        trigger: 'click', //修改触发方式
        format: 'yyyy-MM-dd'
    });

    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){

        $('.save-btn').on('click',function () {
            var relatedBeginDate=$("#relatedBeginDate").val();
            var relatedEndDate=$("#relatedEndDate").val();
            if(relatedBeginDate=='' || relatedEndDate==''){
                parent.layer.msg('开始日期和结束日期不能为空！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var relatedRemark=$("#relatedRemark").val();
            if(relatedRemark=='' ){
                parent.layer.msg('备注不能为空！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
                return;
            }
            var selDatas = $relatedTable.bootstrapTable('getSelections');
            if (selDatas.length == 0) {
                layer.msg('请选择要修改的SKU', {icon: 0, shade: [0.8, '#393D49'], time: 1500});
            } else {
                var ids = [], names = [];
                $.each(selDatas, function (i, d) {
                    ids.push(d.id);
                });
                ids = ids.join(',');

                $.post('/sea/operate/relatedSkuPrice/usave.do?relatedRemark='+relatedRemark+'&relatedBeginDate='+relatedBeginDate+'&relatedEndDate='+relatedEndDate+'&ids='+ids,function(data){
                    if( data.ok ){
                        layer.msg(data.msg,{icon:1,time:3000,shade: [0.8, '#393D49']}, function(){
                            $relatedTable.bootstrapTable('refresh');
                            layer.closeAll(); //关闭弹窗
                        });
                    }else{
                        layer.msg(data.msg,{icon:1,time:3000,shade: [0.8, '#393D49']}, function(){
                            $relatedTable.bootstrapTable('refresh');
                            layer.closeAll(); //关闭弹窗
                        });
                    }
                });
            }
        });

        $('.price-btn').on('click',function () {
                layer.open({
                    type:1,
                    title:'确认日期',
                    area:['600px','250px'],
                    skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                    shadeClose:false,
                    resize: false,
                    scrollbar: false,
                    maxmin: false,//出现最大化按钮
                    content:$('#layer_window')
                })
        });



        //指定允许上传的文件类型
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'Listing',
                    field: 'relatedListingName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'relatedChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'relatedSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '颜色',
                    field: 'productColorName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '尺码',
                    field: 'productSizeName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '企划价',
                    field: 'relatedPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '售价',
                    field: 'relatedSalesPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '差价',
                    field: 'relatedDifferences',
                    align: 'center',
                    valign: 'middle',
                    cellStyle: function (v, r) {
                        if (v != null && r.flag ==99 ) {
                            return {
                                classes: 'next'
                            }
                        }else{
                            return {
                                classes: 'pre'
                            }
                        }
                    }
                },{
                    title: '定价时间',
                    field: '',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if (r.relatedBeginDate != null && r.relatedEndDate != null) {
                            return r.relatedBeginDate+'/'+r.relatedEndDate;
                        }

                        return '';
                    }
                },{
                    title: '备注',
                    field: 'relatedRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '运营人员',
                    field: 'relatedOperateName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                $('.record-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        type: 2,
                        closeBtn:false,
                        area: ['100%','100%'],
                        content: ['/sea/operate/relatedSkuPrice/record/main.do?relatedPriceId='+id, 'yes']
                    });
                });
            }
        });
    });
    //操作菜单

    $('.search-btn').on('click',function(){
           $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/operate/relatedSkuPrice/findByCnd.do?'+$('#search-form').serialize() });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/relatedSkuPrice/import/', //上传接口
            data:{},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    function optFormatter(value,row){
        var content= '';
        content+= '<button class="record-btn btn btn-xs btn-default" style="margin-left: 5px;" data-val="'+row.id+'" title="价格变动记录">价格变动记录</button>';
        return content;
    }


    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-sales-btn', //绑定元素,
            accept:'file',
            url: '/sea/operate/relatedSkuPrice/importSales/', //上传接口
            data:{},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/operate/relatedSkuPrice/export.do?'+$('#search-form').serialize();
    });
</script>
</body>
</html>
